package cn.admin.remoting.impl;

import cn.admin.remoting.Connection;
import cn.admin.remoting.IOEventListener;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class LCL_AliveSessionsListener implements
        IOEventListener.ConnectionLifecycleListener {

    private static final CopyOnWriteArrayList<DefaultConnection>
            sessions = new CopyOnWriteArrayList<>();

    @Override
    public void connectionOpened(Connection connection) {
        sessions.add((DefaultConnection) connection);
    }

    @Override
    public void connectionClosed(Connection connection) {
        sessions.remove(connection);
    }

    public static List<DefaultConnection> aliveSessions() {
        return Collections.unmodifiableList(sessions);
    }
}
